package com.example.demo.mapper;

import com.example.demo.entity.CourseVideo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseVideoMapper {
    // 新增课程视频
    @Insert("INSERT INTO course_videos (course_id, title, video_url, duration) VALUES (#{course_id}, #{title}, #{video_url}, #{duration})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertCourseVideo(CourseVideo courseVideo);

    // 删除课程视频
    @Delete("DELETE FROM course_videos WHERE id = #{id}")
    int deleteCourseVideoById(int id);

    // 修改课程视频
    @Update("UPDATE course_videos SET course_id = #{course_id}, title = #{title}, video_url = #{video_url}, duration = #{duration} WHERE id = #{id}")
    int updateCourseVideo(CourseVideo courseVideo);

    // 查询课程视频
    @Select("SELECT * FROM course_videos WHERE id = #{id}")
    CourseVideo selectCourseVideoById(int id);

    // 查询所有课程视频
    @Select("SELECT * FROM course_videos")
    List<CourseVideo> selectAllCourseVideos();

    // 联合查询课程及其视频信息
    @Select("SELECT cv.* FROM course_videos cv JOIN courses c ON cv.course_id = c.id WHERE c.id = #{courseId}")
    List<CourseVideo> selectCourseVideosByCourseId(int courseId);
}